<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script src="resources/expect-cursor-update.js"></script>
<style type="text/css">
    #container {
        padding: 30px;
        cursor: pointer;
        border: 1px solid blue;
    }
    .wait {
        cursor: wait !important;
    }
    iframe {
        width: 300px;
    }
</style>
</head>
<body>
<p id="description"></p>
<div id="container">
    <iframe id="frame" srcdoc="<body style='height: 500px; cursor: text;'></body>"></iframe>
</div>
<div id="console"></div>
<script>
    description("Test that a cursor change that occurs due only to a style change correctly considers iframes.");

    // Ensure the shouldBe calls don't trigger any changes during our testing that could alter behavior.
    setPrintTestResultsLazily();

    if (!window.eventSender) {
        testFailed('This test requires DumpRenderTree');
    }

    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
        window.jsTestIsAsync = true;
    }

    var container = document.getElementById('container');
    
    var y;
    var frame = document.getElementById('frame');

    if (window.eventSender) {
        frame.onload = function() {
            debug('Mouse moved to cursor changing div');
            eventSender.mouseMoveTo(100, container.offsetTop + 5);
            shouldBeEqualToString('internals.getCurrentCursorInfo()', 'type=Hand');

            debug('Changing cursor style');
            container.classList.add('wait');
            expectCursorUpdate('type=Wait', function() {
                debug('');

                debug('Now move mouse onto iframe above cursor changing div');
                y = frame.offsetTop + 10;
                eventSender.mouseMoveTo(100, y);
                shouldBe('document.elementFromPoint(100, y)', 'frame');
                shouldBeTrue('document.elementsFromPoint(100, y).indexOf(container) > 0');
                shouldBeFalse('internals.cursorUpdatePending');
                shouldBeEqualToString('internals.getCurrentCursorInfo()', 'type=IBeam');
                debug('');

                debug('Changing cursor style of the background should not affect the cursor as it sits over the iframe');
                container.classList.remove('wait');
                expectCursorUpdate('type=IBeam', function() {
                    finishJSTest();
                }); 
            });
        };

    } else {
        function toggleCursorInMainFrame() {
            container.classList.toggle('cursor');
            requestAnimationFrame(toggleCursorInMainFrame);
        }
        requestAnimationFrame(toggleCursorInMainFrame);
    }
</script>
</body>
</html>
